#include<iostream>
#include<cstdio>
using namespace std;
bool f[200005];int n,T,mx,a[200005];
void work(int fx,int xf){
    f[fx]=xf;
    if(fx==1){
        int ans=0;
        for(int i=1;i<=n;i++){
            for(int j=i-1;j>=1;j--){
                if(a[j]==a[i]&&f[j]==f[i])
                    ans+=a[i];
            }
        }
        mx=max(mx,ans);
        return;
    }
    work(fx+1,0);
    work(fx+1,1);
    return;
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>T;
    while(T--){
        cin>>n;mx=0;
        for(int i=1;i<=n;i++)
            cin>>a[i];
        work(1,0);
        work(1,1);
        cout<<mx<<endl;
    }
    return 0;
}
